<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/boost/date_time/microsec_time_clock.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../index.html">top level</a> - <a href="index.html">usr/include/boost/date_time</a> - microsec_time_clock.hpp<span style="font-size: 80%;"> (source / <a href="microsec_time_clock.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">11</td>
            <td class="headerCovTableEntry">11</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">1</td>
            <td class="headerCovTableEntry">1</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #ifndef DATE_TIME_HIGHRES_TIME_CLOCK_HPP___</a>
<span class="lineNum">       2 </span>            : #define DATE_TIME_HIGHRES_TIME_CLOCK_HPP___
<span class="lineNum">       3 </span>            : 
<span class="lineNum">       4 </span>            : /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
<span class="lineNum">       5 </span>            :  * Use, modification and distribution is subject to the
<span class="lineNum">       6 </span>            :  * Boost Software License, Version 1.0. (See accompanying
<span class="lineNum">       7 </span>            :  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
<span class="lineNum">       8 </span>            :  * Author: Jeff Garland, Bart Garst
<span class="lineNum">       9 </span>            :  * $Date$
<span class="lineNum">      10 </span>            :  */
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : /*! @file microsec_time_clock.hpp
<span class="lineNum">      14 </span>            :   This file contains a high resolution time clock implementation.
<span class="lineNum">      15 </span>            : */
<span class="lineNum">      16 </span>            : 
<span class="lineNum">      17 </span>            : #include &lt;boost/cstdint.hpp&gt;
<span class="lineNum">      18 </span>            : #include &lt;boost/shared_ptr.hpp&gt;
<span class="lineNum">      19 </span>            : #include &lt;boost/detail/workaround.hpp&gt;
<span class="lineNum">      20 </span>            : #include &lt;boost/date_time/compiler_config.hpp&gt;
<span class="lineNum">      21 </span>            : #include &lt;boost/date_time/c_time.hpp&gt;
<span class="lineNum">      22 </span>            : #include &lt;boost/date_time/time_clock.hpp&gt;
<span class="lineNum">      23 </span>            : #include &lt;boost/date_time/filetime_functions.hpp&gt;
<span class="lineNum">      24 </span>            : 
<span class="lineNum">      25 </span>            : #ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK
<span class="lineNum">      26 </span>            : 
<span class="lineNum">      27 </span>            : namespace boost {
<span class="lineNum">      28 </span>            : namespace date_time {
<span class="lineNum">      29 </span>            : 
<span class="lineNum">      30 </span>            :   //! A clock providing microsecond level resolution
<span class="lineNum">      31 </span>            :   /*! A high precision clock that measures the local time
<span class="lineNum">      32 </span>            :    *  at a resolution up to microseconds and adjusts to the
<span class="lineNum">      33 </span>            :    *  resolution of the time system.  For example, for the
<span class="lineNum">      34 </span>            :    *  a library configuration with nano second resolution,
<span class="lineNum">      35 </span>            :    *  the last 3 places of the fractional seconds will always
<span class="lineNum">      36 </span>            :    *  be 000 since there are 1000 nano-seconds in a micro second.
<span class="lineNum">      37 </span>            :    */
<span class="lineNum">      38 </span>            :   template&lt;class time_type&gt;
<span class="lineNum">      39 </span>            :   class microsec_clock
<span class="lineNum">      40 </span>            :   {
<span class="lineNum">      41 </span>            :   private:
<span class="lineNum">      42 </span>            :     //! Type for the function used to convert time_t to tm
<span class="lineNum">      43 </span>            :     typedef std::tm* (*time_converter)(const std::time_t*, std::tm*);
<span class="lineNum">      44 </span>            : 
<span class="lineNum">      45 </span>            :   public:
<span class="lineNum">      46 </span>            :     typedef typename time_type::date_type date_type;
<span class="lineNum">      47 </span>            :     typedef typename time_type::time_duration_type time_duration_type;
<span class="lineNum">      48 </span>            :     typedef typename time_duration_type::rep_type resolution_traits_type;
<span class="lineNum">      49 </span>            : 
<span class="lineNum">      50 </span>            :     //! return a local time object for the given zone, based on computer clock
<span class="lineNum">      51 </span>            :     //JKG -- looks like we could rewrite this against universal_time
<span class="lineNum">      52 </span>            :     template&lt;class time_zone_type&gt;
<span class="lineNum">      53 </span>            :     static time_type local_time(shared_ptr&lt;time_zone_type&gt; tz_ptr)
<span class="lineNum">      54 </span>            :     {
<span class="lineNum">      55 </span>            :       typedef typename time_type::utc_time_type utc_time_type;
<span class="lineNum">      56 </span>            :       typedef second_clock&lt;utc_time_type&gt; second_clock;
<span class="lineNum">      57 </span>            :       // we'll need to know the utc_offset this machine has
<span class="lineNum">      58 </span>            :       // in order to get a utc_time_type set to utc
<span class="lineNum">      59 </span>            :       utc_time_type utc_time = second_clock::universal_time();
<span class="lineNum">      60 </span>            :       time_duration_type utc_offset = second_clock::local_time() - utc_time;
<span class="lineNum">      61 </span>            :       // use micro clock to get a local time with sub seconds
<span class="lineNum">      62 </span>            :       // and adjust it to get a true utc time reading with sub seconds
<span class="lineNum">      63 </span>            :       utc_time = microsec_clock&lt;utc_time_type&gt;::local_time() - utc_offset;
<span class="lineNum">      64 </span>            :       return time_type(utc_time, tz_ptr);
<span class="lineNum">      65 </span>            :     }
<span class="lineNum">      66 </span>            : 
<span class="lineNum">      67 </span>            :     //! Returns the local time based on computer clock settings
<span class="lineNum">      68 </span>            :     static time_type local_time()
<span class="lineNum">      69 </span>            :     {
<span class="lineNum">      70 </span><span class="lineCov">      41406 :       return create_time(&amp;c_time::localtime);</span>
<span class="lineNum">      71 </span>            :     }
<span class="lineNum">      72 </span>            : 
<span class="lineNum">      73 </span>            :     //! Returns the UTC time based on computer settings
<span class="lineNum">      74 </span>            :     static time_type universal_time()
<span class="lineNum">      75 </span>            :     {
<span class="lineNum">      76 </span>            :       return create_time(&amp;c_time::gmtime);
<span class="lineNum">      77 </span>            :     }
<a name="78"><span class="lineNum">      78 </span>            : </a>
<span class="lineNum">      79 </span>            :   private:
<span class="lineNum">      80 </span><span class="lineCov">      41406 :     static time_type create_time(time_converter converter)</span>
<span class="lineNum">      81 </span>            :     {
<span class="lineNum">      82 </span>            : #ifdef BOOST_HAS_GETTIMEOFDAY
<span class="lineNum">      83 </span>            :       timeval tv;
<span class="lineNum">      84 </span><span class="lineCov">      41406 :       gettimeofday(&amp;tv, 0); //gettimeofday does not support TZ adjust on Linux.</span>
<span class="lineNum">      85 </span><span class="lineCov">      41406 :       std::time_t t = tv.tv_sec;</span>
<span class="lineNum">      86 </span><span class="lineCov">      41406 :       boost::uint32_t sub_sec = tv.tv_usec;</span>
<span class="lineNum">      87 </span>            : #elif defined(BOOST_HAS_FTIME)
<span class="lineNum">      88 </span>            :       winapi::file_time ft;
<span class="lineNum">      89 </span>            :       winapi::get_system_time_as_file_time(ft);
<span class="lineNum">      90 </span>            :       uint64_t micros = winapi::file_time_to_microseconds(ft); // it will not wrap, since ft is the current time
<span class="lineNum">      91 </span>            :                                                                // and cannot be before 1970-Jan-01
<span class="lineNum">      92 </span>            :       std::time_t t = static_cast&lt;std::time_t&gt;(micros / 1000000UL); // seconds since epoch
<span class="lineNum">      93 </span>            :       // microseconds -- static casts suppress warnings
<span class="lineNum">      94 </span>            :       boost::uint32_t sub_sec = static_cast&lt;boost::uint32_t&gt;(micros % 1000000UL);
<span class="lineNum">      95 </span>            : #else
<span class="lineNum">      96 </span>            : #error Internal Boost.DateTime error: BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK is defined, however neither gettimeofday nor FILETIME support is detected.
<span class="lineNum">      97 </span>            : #endif
<span class="lineNum">      98 </span>            : 
<span class="lineNum">      99 </span>            :       std::tm curr;
<span class="lineNum">     100 </span><span class="lineCov">      41406 :       std::tm* curr_ptr = converter(&amp;t, &amp;curr);</span>
<span class="lineNum">     101 </span><span class="lineCov">      41406 :       date_type d(static_cast&lt; typename date_type::year_type::value_type &gt;(curr_ptr-&gt;tm_year + 1900),</span>
<span class="lineNum">     102 </span><span class="lineCov">      41406 :                   static_cast&lt; typename date_type::month_type::value_type &gt;(curr_ptr-&gt;tm_mon + 1),</span>
<span class="lineNum">     103 </span><span class="lineCov">     165624 :                   static_cast&lt; typename date_type::day_type::value_type &gt;(curr_ptr-&gt;tm_mday));</span>
<span class="lineNum">     104 </span>            : 
<span class="lineNum">     105 </span>            :       //The following line will adjust the fractional second tick in terms
<span class="lineNum">     106 </span>            :       //of the current time system.  For example, if the time system
<span class="lineNum">     107 </span>            :       //doesn't support fractional seconds then res_adjust returns 0
<span class="lineNum">     108 </span>            :       //and all the fractional seconds return 0.
<span class="lineNum">     109 </span>            :       int adjust = static_cast&lt; int &gt;(resolution_traits_type::res_adjust() / 1000000);
<span class="lineNum">     110 </span>            : 
<span class="lineNum">     111 </span>            :       time_duration_type td(static_cast&lt; typename time_duration_type::hour_type &gt;(curr_ptr-&gt;tm_hour),
<span class="lineNum">     112 </span>            :                             static_cast&lt; typename time_duration_type::min_type &gt;(curr_ptr-&gt;tm_min),
<span class="lineNum">     113 </span>            :                             static_cast&lt; typename time_duration_type::sec_type &gt;(curr_ptr-&gt;tm_sec),
<span class="lineNum">     114 </span><span class="lineCov">      41406 :                             sub_sec * adjust);</span>
<span class="lineNum">     115 </span>            : 
<span class="lineNum">     116 </span><span class="lineCov">      41406 :       return time_type(d,td);</span>
<span class="lineNum">     117 </span>            :     }
<span class="lineNum">     118 </span>            :   };
<span class="lineNum">     119 </span>            : 
<span class="lineNum">     120 </span>            : 
<span class="lineNum">     121 </span>            : } } //namespace date_time
<span class="lineNum">     122 </span>            : 
<span class="lineNum">     123 </span>            : #endif //BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK
<span class="lineNum">     124 </span>            : 
<span class="lineNum">     125 </span>            : 
<span class="lineNum">     126 </span>            : #endif
<span class="lineNum">     127 </span>            : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
